<?php
ob_start();
session_start();
require("../conn.php");
     
         $menuid=$_POST['menu_id'];
		$vi_name=($_POST['vi_name']);
		 $en_name=($_POST['en_name']);
		 $URL=  $_POST['link_url'];
		 $order=$_POST['order'];
		 //echo $_POST["menus"];
		 if($_SESSION['Permit']==1)
		 {
			if($_POST['menus']=='menu')
			{
			 $parent_id=0;
			 $sid=0;
			}
			else if($_POST['menus']=='article') 
			{
			 $parent_id=$_POST['section_id'];
			 $sid=-1;
			}
			 else 
			 { 
               $parent_id=$_POST['parent_id'];
			   $sid=$_POST['sid'];
			  // echo $sid;
			 }
			   $sql=sprintf("update tblmenu set URl='%s',vi_name='%s',en_name='%s',tblmenu.order='%s',parent_id='%s',section_id='%s' where id='%s'", $URL,$vi_name,$en_name,$order,$parent_id,$sid,$menuid);	
			   //echo $sql;
			$kq=mysql_query($sql)or die(mysql_error());
	 
	
	
			
			 
				
		 }
		 else
		 {
			if($_POST['menus']=='article') 
			{
			$parent_id=$_POST['section_id'];
			$sql=sprintf("update tblmenu set URl='%s',vi_name='%s',en_name='%s',tblmenu.order='%s',parent_id='%s' where id='%s'", $URL,$vi_name,$en_name,$order,$parent_id,$menuid);																														
			$kq=mysql_query($sql)or die(mysql_error());
			}
			else
			{
			$sql=sprintf("update tblmenu set URl='%s',vi_name='%s',en_name='%s',tblmenu.order='%s' where id='%s'", $URL,$vi_name,$en_name,$order,$menuid);					
			echo $sql;																									
			$kq=mysql_query($sql)or die(mysql_error());
			}
 
		 }

         
if(!$kq)
			{
				?>
				<script language="javascript">
				alert("Sửa menu không thành công!");
			
				</script>
				<?php
					header("Location:menue?id=".$menuid);
			}
			else
			{
				
				?>
				<script language="javascript">
				alert("Sửa menu thành công!");
			
				</script>
				<?php
			   
				header("Location:../menulist");
				
			}
		

?>
